import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:niuniu/pages/login/privacy_policy/controller.dart';
import 'package:get/get.dart';
import 'package:webview_flutter/webview_flutter.dart';

class PrivacyPolicyPage extends GetView<PrivacyPolicyController> {
  const PrivacyPolicyPage({Key? key}) : super(key: key);

  // 主视图
  Widget buildView() {
    return Container(
      padding: EdgeInsets.only(left: 15.w, right: 15.w),
      child: Center(
          child: WebViewWidget(controller: WebViewController()
            ..setJavaScriptMode(JavaScriptMode.unrestricted)
            ..setBackgroundColor(const Color(0x00000000))
            ..setNavigationDelegate(
              NavigationDelegate(
                onProgress: (int progress) {
                  // Update loading bar.
                },
                onPageStarted: (String url) {},
                onPageFinished: (String url) {},
                onWebResourceError: (WebResourceError error) {},
                // onNavigationRequest: (NavigationRequest request) {
                //   if (request.url.startsWith('https://www.youtube.com/')) {
                //     return NavigationDecision.prevent;
                //   }
                //   return NavigationDecision.navigate;
                // },
              ),
            )
            ..loadRequest(Uri.parse('https://www.ixigua.com/privacy_policy')))
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PrivacyPolicyController>(
      init: PrivacyPolicyController(),
      id: "privacy-policy-page",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("隐私政策")),
          body: SafeArea(child: Container(
            margin: EdgeInsets.only(top: 10.h, bottom: 10.h),
            child: buildView(),
          )),
        );
      },
    );
  }
}
